
	import util from '@/libs/util';
	import spr from '@/sprcore/common';
	import axios from 'axios';
	export default {
		data() {
			return {
				columns: [
										{
						title: '菜单代码',
						key: 'menuCode'
					},		
					{
						title: '菜单名称',
						key: 'menuName'
					},		
					{
						title: '排序',
						key: 'no'
					},		
					{
						title: 'Action',
						key: 'action',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '5px',
										display:this.p_uucMenu_update?"":"none",
									},
									on: {
										click: () => {
											let that = this;
											that.form_update(that.list_datas[params.index].id);
										}
									}
								}, '查看编辑'),
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									style: {
										display:this.p_uucMenu_delete?"":"none",
									},									
									on: {
										click: () => {
											let that = this;
											//that.remove(params.index);
							                this.$Modal.confirm({
							                    title: '操作提示',
							                    content: '<p>确认是否删除此记录</p>',
							                    onOk: () => {
							                        that.form_handleDelete(that.list_datas[params.index].id);
							                    },
							                    onCancel: () => {
							                    }
							                });											
										}
									}
								}, '删除')
							]);
						}
					}
				],
				p_uucMenu_create:false,
				p_uucMenu_update:false,
				p_uucMenu_delete:false,			
				list_searchKey:'',
				list_datas: [],
				list_totalCount: 0,
				list_pageSize:spr.constants.list_pageSize,
				list_pageNo:1,
				
				form_createOrUpdateModalLoading: true,
				form_createOrUpdateModal: false,
				form_createOrUpdateModalTitle: '',
				form_createOrUpdateItemForm: {
					menuCode: '',
					menuName: '',
					parentId: '',
					url: '',
					privilegeId: '',
					no: '',
					memo: '',
					id: '',	
				},
				form_createOrUpdateItemFormRuleValidate: {
					menuCode: [
					{required: true,message: '不能为空',	trigger: 'blur'},					
					],
					menuName: [
					{required: true,message: '不能为空',	trigger: 'blur'},					
					],
					parentId: [
					],
					url: [
					],
					privilegeId: [
					],
					no: [
					{required: true,message: '不能为空',	trigger: 'blur'},					
					],
					memo: [
					],
				},
				form_loading_menuCode:false	,
				formdata_menuCode:[],				
				form_loading_menuName:false	,
				formdata_menuName:[],				
				form_loading_parentId:false	,
				formdata_parentId:[],				
				form_loading_url:false	,
				formdata_url:[],				
				form_loading_privilegeId:false	,
				formdata_privilegeId:[],				
				form_loading_no:false	,
				formdata_no:[],				
				form_loading_memo:false	,
				formdata_memo:[],				

				
				
			}
		},
		methods: {
			list_getData() {
				let that = this;
				util.ajax.get('/api/uucMenu/list', {
					params: {
						size: that.list_pageSize,
						offset: that.list_pageSize * ( that.list_pageNo - 1),
						searchKey: that.list_searchKey
					}
				}).then(function(response) {
					that.list_datas = response.data.datas;
					that.list_totalCount = response.data.totalCount;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});

			
				
			},
			list_search(){
				let that = this;
				that.list_getData();
			},
			list_changePage(pageNo){
				let that = this;
				that.list_pageNo = pageNo;
				that.list_getData();
			},		
			list_changePageSize(pageSize){
				let that = this;
				that.list_pageSize = pageSize;
				that.list_getData();
			},				
			list_remove(index) {
				let that = this;
				that.data6.splice(index, 1);
			},
			init_parentId(){//TODO
				return util.ajax.get('/api/uucCommonRemote/listMenu');
			},			
			init_privilegeId(){//TODO
				return util.ajax.get('/api/uucCommonRemote/listPrivilege');
			},			
			form_init(func) {
				let that = this;

				that.form_createOrUpdateModalLoading = true;
				that.form_createOrUpdateModal = true;
				
				that.form_createOrUpdateItemForm.id = '';
				that.form_createOrUpdateItemForm.menuCode = '';
				that.form_createOrUpdateItemForm.menuName = '';
				that.form_createOrUpdateItemForm.parentId = '';
				that.form_createOrUpdateItemForm.url = '';
				that.form_createOrUpdateItemForm.privilegeId = '';
				that.form_createOrUpdateItemForm.no = '';
				that.form_createOrUpdateItemForm.memo = '';
				
/*
				util.ajax.get('/api/uucCommonRemote/listMenu', {
					params: {}
				}).then(function(response) {
					that.formdata_parentId = response.data.datas;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});						
				util.ajax.get('/api/uucCommonRemote/listPrivilege', {
					params: {}
				}).then(function(response) {
					that.formdata_privilegeId = response.data.datas;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});						
*/				
				axios.all([that.init_parentId(),that.init_privilegeId(),])
				.then(axios.spread(function (response_parentId,response_privilegeId,) {			
					that.formdata_parentId = response_parentId.data.datas;	
					that.formdata_privilegeId = response_privilegeId.data.datas;	
					func();
				}));			
				
			},
			form_create() {
				let that = this;
				that.form_init(function(){
					that.form_createOrUpdateModalTitle = "新增菜单管理";
				});
				
			},
			form_update(id) {
				let that = this;
				that.form_init(function(){
					that.form_createOrUpdateModalTitle = "修改菜单管理";
					util.ajax.get('/api/uucMenu/get', {
						params: {
							id: id
						}
					}).then(function(response) {
						let data = response.data;					
						that.form_createOrUpdateItemForm.id = data.id;
						that.form_createOrUpdateItemForm.menuCode = data.menuCode;
						that.form_createOrUpdateItemForm.menuName = data.menuName;
						that.form_createOrUpdateItemForm.parentId = data.parentId;
						that.form_createOrUpdateItemForm.url = data.url;
						that.form_createOrUpdateItemForm.privilegeId = data.privilegeId;
						that.form_createOrUpdateItemForm.no = data.no;
						that.form_createOrUpdateItemForm.memo = data.memo;
					}).catch(function(error) {
						spr.errNotify(that,error);
					});					
				});

			},
			form_handlecreateOrUpdateItemForm() {
				let that = this;
				that.form_createOrUpdateModal = true;
				that.$refs['form_createOrUpdateItemForm'].validate((valid) => {
					if(!valid) {
						that.form_createOrUpdateModalLoading = false;
						that.$nextTick(() => {that.form_createOrUpdateModalLoading = true;});
					} else {
						util.ajax.post('/api/uucMenu/createOrUpdate', {
							menuCode: that.form_createOrUpdateItemForm.menuCode,
							menuName: that.form_createOrUpdateItemForm.menuName,
							parentId: that.form_createOrUpdateItemForm.parentId,
							url: that.form_createOrUpdateItemForm.url,
							privilegeId: that.form_createOrUpdateItemForm.privilegeId,
							no: that.form_createOrUpdateItemForm.no,
							memo: that.form_createOrUpdateItemForm.memo,
							id: that.form_createOrUpdateItemForm.id
						}).then(function(response) {
							that.$Message.info('保存成功!');
							that.form_createOrUpdateModal = false;
							that.list_getData();
						}).catch(function(error) {
							that.form_createOrUpdateModalLoading = false;
							that.$nextTick(() => {that.form_createOrUpdateModalLoading = true;});							
							spr.errNotify(that,error);
						});
					}
				});
			},
			form_handleDelete(id){
				let that = this;
				util.ajax.post('/api/uucMenu/delete', {
					id: id
				}).then(function(response) {
					that.$Message.info('记录删除成功!');
					that.list_getData();
				}).catch(function(error) {
					console.log(error);
				});				
			},

			form_getdata_parentId(query){
				let that = this;
				that.loading_parentId = true;
				util.ajax.get('/api/uucCommonRemote/listMenu', {
					params: {
						searchKey:query
					}
				}).then(function(response) {
					that.formdata_parentId = response.data.datas;
					that.loading_parentId = false;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});					                			
			},				
			form_getdata_privilegeId(query){
				let that = this;
				that.loading_privilegeId = true;
				util.ajax.get('/api/uucCommonRemote/listPrivilege', {
					params: {
						searchKey:query
					}
				}).then(function(response) {
					that.formdata_privilegeId = response.data.datas;
					that.loading_privilegeId = false;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});					                			
			},				
			privilege_button(){
				let that = this;
				util.ajax.post('/api/uucLogin/hasPrivilege', {
					privilegeCodes:["uucMenu_create","uucMenu_update","uucMenu_delete"],
				}).then(function(response) {
					let datas = response.data.datas;
					that.p_uucMenu_create = spr._hasPrivilegeWhenPageLoaded(datas,"uucMenu_create");
					that.p_uucMenu_update = spr._hasPrivilegeWhenPageLoaded(datas,"uucMenu_update");
					that.p_uucMenu_delete = spr._hasPrivilegeWhenPageLoaded(datas,"uucMenu_delete");					
				}).catch(function(error) {
					spr.errNotify(that,error);
				});					
			},
			
		},
		created() {
			let that = this;
			that.privilege_button();
			that.list_getData();
		}
	}